// toast.ts
import {createApp, h} from 'vue';
import Toast from './index.vue';

// 创建一个容器用于挂载 Toast
const container = document.createElement('div');
document.body.appendChild(container);

export function showToast(message: string, type: 'success' | 'warning' | 'error' | 'info' = 'info', duration?: number) {
    const app = createApp({
        render() {
            return h(Toast, {message, type, duration});
        },
    });

    // 挂载组件
    app.mount(container);

    // 自动卸载组件
    setTimeout(() => {
        app.unmount();
    }, duration || 1000);
}